package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.MarketData;
import sanrenxing.dayEnd.backRepertoryTotal.domain.MarketDataT;

import java.util.List;

/**
 * @desrciption 行情数据 dao层
 * @auth：yidu  李小锋
 * @date:2021/3/13 0013 - 15:38
 * @version:1:0
 */
@Repository
public interface MarketDataDao {
    /**
     * 新增一行数据
     * @param marketData 对象
     * @return 0、增加失败 1、增加成功
     */
    @Insert("insert into marketData(marketId,seId,inputDate,openPrice,closePrice,notes)" +
            "values(Id=#{marketId},seId=#{seId},inputDate=#{inputDate},openPrice=#{openPrice},closePrice=#{closePrice},notes=#{notes})")
    public int add(MarketData marketData);

    @Insert("insert into marketData(Id,seId,inputDate,openPrice,closePrice,notes)" +
            "values(#{marketId},#{seId},to_date('${inputDate}','yyyy-MM-dd'),#{openPrice},#{closePrice},#{notes})")
    public int addExcl(MarketDataT marketData);
    /**
     * 删除一行数据
     * @param marketId 编号
     * @return 0、删除失败 1、删除成功
     */
    @Delete("delete from marketData where Id=#{marketId}")
    public int delete(@Param("marketId") int marketId);
    /**
     * 修改一行数据
     * @param marketData 对象
     * @return 0、修改失败 1、修改成功
     */
    @Update("update marketData set seId=#{seId},inputDate=#{inputDate},openPrice=#{openPrice},closePrice=#{closePrice},notes=#{notes} " +
            "where Id=#{marketId}")
    public int update(MarketData marketData);
    /**
     * 查询所有的订单数据
     * @return 返回一个订单集合
     */
    @Select("select * from marketData")
    @Results(id = "marketMap",value = {
            @Result(id = true,column = "Id",property = "marketId"),
            @Result(column = "seId",property = "seId"),
            @Result(column = "inputDate",property = "inputDate"),
            @Result(column = "openPrice",property = "openPrice"),
            @Result(column = "closePrice",property = "closePrice"),
            @Result(column = "notes",property = "notes")
    })
    public List<MarketData> findAll();
    /**
     * 分页查询
     * @param start  开始行号
     * @param rows   每页行数
     * @param condition 查询条件
     * @return 集合
     */
    @ResultMap(value = "marketMap")
    @Select("<script>"+
            "select * from " +
            "(select rownum rn, marketData.* from marketData " +
            "<where> #{rows}>rownum </where>)"+
            "<where> " +
            " ${condition}" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>"
    )
    public List<MarketData> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);
    /**
     * 按条件统计出记录行数
     * @param condition 条件
     * @return 记录行数
     */
    @Select("select count(*) from marketData where 1=1 ${condition}")
    public int count(String condition);
}
